<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>v-for 实例</title>
    <script type="text/javascript" src="../assets/js/vue.js"></script>
</head>

<body>
    <h1>v-for 实例</h1>
    <hr>
    <div id="app">
        <ul>
            <li v-for="item in Sortitems">
                {{item}}
            </li>
        </ul>
        <hr>
        <ul>
            <li v-for="(student,index) in students">
                {{index+1}}:{{student.name}}-{{student.age}}
            </li>
        </ul>
        <table border="1" style="border-collapse:collapse">
            <thead>
                <tr>
                        <td>序号 </td>
                    <td>姓名 </td>
                    <td>年龄</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="(student,index) in students">
                    <td>

                        {{index+1}}

                    </td>

                    <td>

                        {{student.name}}

                    </td>

                    <td>
                        {{student.age}}

                    </td>
                </tr>
            </tbody>

        </table>
    </div>
    <script type="text/javascript">
        var app = new Vue({
            el: '#app',
            data: {
                items: [9, 11, 2, 3, 4, 25, 6, 7],
                students: [
                    { name: 'jyue1', age: 33 },
                    { name: 'pyue2', age: 38 },
                    { name: 'pyue3', age: 33 },
                    { name: 'kyue4', age: 33 },
                ]
            },
            computed: {
                Sortitems: function () {
                    return this.items.sort(sortNumber);
                }
            }

        })
        function sortNumber(a, b) {
            return a - b;
        }
    </script>
</body>

</html>